import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'
import qs from 'qs'
const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}

// const baseUrlTpm = CommonConfig.tpmUrl + '/v1'
// const baseUrlUpms = CommonConfig.upmsUrl + '/v1'
// const baseUrlProcess = CommonConfig.processUrl + '/v1'
// const baseUrlPlanning = CommonConfig.planningUrl + '/v1'

const baseUrlTpm = CommonConfig.tpmUrl + '/v1/minio'
// const baseUrlUpms = CommonConfig.upmsUrl + '/v1/minio'
const baseUrlProcess = CommonConfig.processUrl + '/v1/minio'
const baseUrlPlanning = CommonConfig.planningUrl + '/v1/minio'
const datacenterUrl = CommonConfig.datacenterUrl + '/v1/minio'
const cutterUrl = CommonConfig.cutterUrl + '/v1'

// 下载设备台帐模版
export function downloadTPM () {
  const newUrl = `${baseUrlTpm}/devices/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 下载用户管理模版
export function downloadUser () {
  const newUrl = `${datacenterUrl}/users/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 下载产品模版
export function downloadProduct () {
  const newUrl = `${baseUrlProcess}/products/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 下载工序模版
export function downloadProcess () {
  const newUrl = `${baseUrlProcess}/working_steps/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 下载车间计划模版
export function downloadPlantPlan () {
  const newUrl = `${baseUrlPlanning}/workshop_plannings/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
// 下载刀具台账模版
export function downloadCutter () {
  const newUrl = `${cutterUrl}/cutter_catalogue/minio/download`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 下载工艺路线模版
export function downloadProcessRoutes (productIds) {
  const newUrl = `${baseUrlProcess}/process_routes/download`
  let config = {
    params: {
      productIds
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.get(newUrl, config).then((res) => {
    return Promise.resolve(res)
  })
}
